bitkeeper revision 1.1041.3.3 (40e52970DgkhtxD_Mq--sUEE6uPUZg)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Fri, 2 Jul 2004 09:22:56 +0000 (09:22 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Fri, 2 Jul 2004 09:22:56 +0000 (09:22 +0000)
Change console cleanup for domains so that it gets called
when the domain channel goes away. Stops console listeners
hanging around.

tools/python/xen/xend/server/blkif.py
tools/python/xen/xend/server/channel.py
tools/python/xen/xend/server/console.py
tools/python/xen/xend/server/controller.py
tools/python/xen/xend/server/netif.py

index 7310494377548cb3399cc98ef4d7fa750c47d8a8..d265ae382e02b3142268e1586de2f0ba88f9b1fe 100755 (executable)
@@ -210,9 +210,6 @@ class BlkifController(controller.Controller):
                         self.evtchn['port2']])
         return val
 
-    def lostChannel(self):
-        controller.Controller.lostChannel(self)
-
     def getDevices(self):
         return self.devices.values()
 
index 0c9d316dec46ede987082250dd391cc587cd60e4..caaa66e28c744333c1d0e39fe278f4a9f2b53d59 100755 (executable)
@@ -174,9 +174,9 @@ class VirqChannel(BaseChannel):
         """Close the channel. Calls lostChannel(self) on all its clients and
         channelClosed() on the factory.
         """
-        for c in self.clients:
+        for c in self.clients[:]:
             c.lostChannel(self)
-        del self.clients
+        self.clients = []
         BaseChannel.close(self)
 
     def registerClient(self, client):
@@ -238,7 +238,7 @@ class Channel(BaseChannel):
         """
         if self.closed: return
         self.closed = 1
-        for d in self.devs:
+        for d in self.devs[:]:
             d.lostChannel()
         self.factory.channelClosed(self)
         self.devs = []
index 336ccacca0c4b51cfb51e0b97717d39379993468..77f6343c3d10c427da9bc030255accfa28525573 100755 (executable)
@@ -93,10 +93,15 @@ class ConsoleController(controller.Controller):
     output and the connected TCP sockets to post console input.
     """
 
+    STATUS_NEW       = 'new'
+    STATUS_CLOSED    = 'closed'
+    STATUS_CONNECTED = 'connected'
+    STATUS_LISTENING = 'listening'
+
     def __init__(self, factory, dom, console_port):
         controller.Controller.__init__(self, factory, dom)
         self.majorTypes = [ CMSG_CONSOLE ]
-        self.status = "new"
+        self.status = self.STATUS_NEW
         self.addr = None
         self.conn = None
         self.rbuf = xu.buffer()
@@ -123,28 +128,31 @@ class ConsoleController(controller.Controller):
         return not (self.closed() or self.rbuf.empty())
 
     def closed(self):
-        return self.status == 'closed'
+        return self.status == self.STATUS_CLOSED
 
     def connected(self):
-        return self.status == 'connected'
+        return self.status == self.STATUS_CONNECTED
 
     def close(self):
-        try:
-            self.status = "closed"
-            if self.conn:
-                self.conn.loseConnection()
-            self.listener.stopListening()
-            self.deregisterChannel()
-            self.lostChannel()
-        except Exception, ex:
-            print 'ConsoleController>close>', ex
-            raise
+        """Close the console controller.
+        """
+        self.lostChannel()
+
+    def lostChannel(self):
+        """The channel to the domain has been lost.
+        Cleanup: disconnect TCP connections and listeners, notify the controller.
+        """
+        self.status = self.STATUS_CLOSED
+        if self.conn:
+            self.conn.loseConnection()
+        self.listener.stopListening()
+        controller.Controller.lostChannel(self)
 
     def listen(self):
         """Listen for TCP connections to the console port..
         """
         if self.closed(): return
-        self.status = "listening"
+        self.status = self.STATUS_LISTENING
         if self.listener:
             #self.listener.startListening()
             pass
@@ -153,15 +161,25 @@ class ConsoleController(controller.Controller):
             self.listener = reactor.listenTCP(self.console_port, f)
 
     def connect(self, addr, conn):
+        """Connect a TCP connection to the console.
+        Fails if closed or already connected.
+
+        addr peer address
+        conn connection
+
+        returns 0 if ok, negative otherwise
+        """
         if self.closed(): return -1
         if self.connected(): return -1
         self.addr = addr
         self.conn = conn
-        self.status = "connected"
+        self.status = self.STATUS_CONNECTED
         self.handleOutput()
         return 0
 
     def disconnect(self):
+        """Disconnect the TCP connection to the console.
+        """
         if self.conn:
             self.conn.loseConnection()
         self.addr = None
@@ -169,15 +187,29 @@ class ConsoleController(controller.Controller):
         self.listen()
 
     def requestReceived(self, msg, type, subtype):
+        """Receive console data from the console channel.
+
+        msg     console message
+        type    major message type
+        subtype minor message typ
+        """
         self.rbuf.write(msg.get_payload())
         self.handleOutput()
         
     def responseReceived(self, msg, type, subtype):
-        # Just ignore responses.
+        """Handle a response to a request written to the console channel.
+        Just ignore it because the return values are not interesting.
+
+        msg     console message
+        type    major message type
+        subtype minor message typ
+        """
         pass
 
     def produceRequests(self):
-        # Send as much pending console data as there is room for.
+        """Write pending console data to the console channel.
+        Writes as much to the channel as it can.
+        """
         work = 0
         while not self.wbuf.empty() and self.channel.writeReady():
             msg = xu.message(CMSG_CONSOLE, 0, 0)
@@ -187,7 +219,12 @@ class ConsoleController(controller.Controller):
 
     def handleInput(self, conn, data):
         """Handle some external input aimed at the console.
-        Called from a TCP connection (conn).
+        Called from a TCP connection (conn). Ignores the input
+        if the calling connection (conn) is not the one connected
+        to the console (self.conn).
+
+        conn connection
+        data input data
         """
         if self.closed(): return -1
         if conn != self.conn: return 0
index 299bd621f67d40c3635f06bb452c5b9bf833a2cc..49d6e26ea890ca70ee318d0ddd78f3028f0c3b7b 100755 (executable)
@@ -205,12 +205,12 @@ class Controller(CtrlMsgRcvr):
     def close(self):
         """Close the controller.
         """
-        self.deregisterChannel()
         self.lostChannel()
 
     def lostChannel(self):
         """The controller channel has been lost.
         """
+        self.deregisterChannel()
         self.factory.instanceClosed(self)
 
 class Dev:
index 5760552e8b69757066a5148ff305dbfa3d56c71c..0096511b7c25898bb035d1e2a462f30c933bff37 100755 (executable)
@@ -198,8 +198,9 @@ class NetifController(controller.Controller):
     def randomMAC(self):
         """Generate a random MAC address.
 
-        The OUI (Organisation Unique Identifier) used is AA:00:00, which
-        is a currently unassigned one that used to belong to DEC.
+        Uses OUI (Organizationally Unique Identifier) AA:00:00, an
+        unassigned one that used to belong to DEC. The OUI list is
+        available at 'standards.ieee.org'.
 
         The remaining 3 fields are random, with the first bit of the first
         random field set 0.